package com.jerry.mingxing.ui.fashionnew;

import android.os.Handler;
import android.util.Log;

import com.jerry.mingxing.bean.NewBean;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2016/8/31.
 */
public class FashionNewPresenter implements FashionNewContract.Presenter{
    private FashionNewContract.Mode mode;
    private FashionNewContract.View view;

    public  FashionNewPresenter(FashionNewContract.View view){
        this.view = view;
        this.mode = new FashionNewMode();
    }
    @Override
    public void getData() {
        mode.loadFashionnew(new Callback<NewBean>() {
            @Override
            public void onResponse(Call<NewBean> call, Response<NewBean> response) {
                if (response.isSuccessful()){
                    final NewBean body = response.body();
                    Log.i("mbnbn", "onResponse: ====="+body);
                    Handler handler =new Handler();
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            view.onResponse(body);

                        }
                    });
                }
            }

            @Override
            public void onFailure(Call<NewBean> call, Throwable t) {
                    Handler handler = new Handler();
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                        view.onFailure("加载失败");
                        }
                    });
            }
        });

    }
}
